//首页
const express = require('express');
const { data } = require('jquery');
//引入连接池
const pool = require('../pool')
const Response = require("../utils/Response.js");
const router = express.Router()
router.post("/user/register", (req, res, next) => {
    let { username, password, phone } = req.body // post请求参数在req.body中
    // 表单验证通过，执行添加操作
    let sql = "insert into admin(username,phone,password) values (?,?,?)";
    pool.query(sql, [username, phone, password], (err, r) => {
        if (err) {
            return next(err)
        }
        res.send({ code: 200, msg: '添加成功' })
    });
});
router.post("/user/query/phone", (req, res, next) => {
     let phone  = req.body.phone // post请求参数在req.body中
    // 表单验证通过，执行添加操作
    
    let sql = "select * from admin where  phone=?";
    pool.query(sql, [phone], (err, r) => {
        if(r.length == 0){
            res.send({ code: 200, msg: '该手机号没有注册',r:r})
        }else{
            res.send({ code: 400, msg: '该手机号已经注册' })

        }
    });
});




module.exports = router